<template>
  <div class="home-container">
    <!-- 111111 -->
    <!-- 顶部导航栏 -->
    <van-nav-bar title="智慧零工平台" fixed>
    </van-nav-bar>

    <!-- 内容区域 -->
    <div class="content">
      <!-- 轮播图 -->
      <van-swipe class="banner" :autoplay="3000" indicator-color="#4f46e5">
        <van-swipe-item v-for="(item, index) in banners" :key="index">
          <img :src="item.image" :alt="item.title" class="banner-img" />
        </van-swipe-item>
      </van-swipe>

      <!-- 快速入口 -->
      <van-cell-group inset class="quick-entry">
        <van-grid :column-num="3" :border="false">
          <van-grid-item 
            v-for="(item, index) in quickEntries" 
            :key="index" 
            :icon="item.icon" 
            :text="item.text" 
            @click="goToTaskList()"
          />
        </van-grid>
      </van-cell-group>

      <!-- 热门工种 -->
      <van-cell-group inset class="section" @click="goToTaskList">
        <van-cell title="热门工种" />
        <van-grid :column-num="2" :border="false">
          <van-grid-item v-for="(job, index) in hotJobs" :key="index">
            <template #icon>
              <div class="job-icon" :style="{ backgroundColor: job.bgColor }">
                <van-icon :name="job.icon" color="white" size="24" />
              </div>
            </template>
            <template #text>
              <div class="job-info">
                <div class="job-title">{{ job.title }}</div>
                <div class="job-price">¥{{ job.price }}/{{ job.unit }}</div>
              </div>
            </template>
          </van-grid-item>
        </van-grid>
      </van-cell-group>

      <!-- 服务特点 -->
      <div class="section">
        <div class="section-header">
          <h2>平台优势</h2>
        </div>
        <div class="features">
          <div class="feature-item" v-for="(feature, index) in features" :key="index">
            <van-icon :name="feature.icon" :color="feature.color" size="32" />
            <div class="feature-title">{{ feature.title }}</div>
            <div class="feature-desc">{{ feature.description }}</div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { ref } from 'vue'
import { useRouter } from 'vue-router'

const router = useRouter()
const activeTab = ref(0)

// 跳转到任务列表页面的方法
const goToTaskList = () => {
  router.push('/Mtasklist')
}

// 轮播图数据
const banners = [
  { image: '/image/智慧零工平台轮播图设计 (1).png', title: '智慧零工平台' },
  { image: '/image/智慧零工平台轮播图设计 (2).png', title: '灵活用工' },
  { image: '/image/智慧零工平台轮播图设计 (3).png', title: '安全可靠' },
  { image: '/image/智慧零工平台轮播图设计.png', title: '安全可靠' }
]

// 快速入口数据
const quickEntries = [
  { icon: 'fire-o', text: '热门工种', color: '#4f46e5', route: '/hot-jobs' },
  { icon: 'clock-o', text: '最新发布', color: '#4f46e5', route: '/new-jobs' },
  { icon: 'location-o', text: '附近工作', color: '#4f46e5', route: '/nearby-jobs' },
]

// 热门工种数据
const hotJobs = [
  {
    icon: 'shop-o',
    title: '餐饮服务员',
    price: '150',
    unit: '天',
    bgColor: '#4f46e5'
  },
  {
    icon: 'home-o',
    title: '家政保洁',
    price: '200',
    unit: '次',
    bgColor: '#4f46e5'
  },
  {
    icon: 'logistics',
    title: '快递配送',
    price: '180',
    unit: '天',
    bgColor: '#4f46e5'
  },
  {
    icon: 'manager-o',
    title: '装修工人',
    price: '300',
    unit: '天',
    bgColor: '#4f46e5'
  }
]

// 平台特点数据
const features = [
  {
    icon: 'shield-o',
    title: '安全保障',
    description: '实名认证、保险保障、资金托管',
    color: '#4f46e5'
  },
  {
    icon: 'clock-o',
    title: '快速接单',
    description: '智能匹配、一键接单、灵活时间',
    color: '#4f46e5'
  },
  {
    icon: 'balance-o',
    title: '公平交易',
    description: '明码标价、评价体系、争议处理',
    color: '#4f46e5'
  },
  {
    icon: 'service-o',
    title: '专业服务',
    description: '技能培训、职业发展、持续支持',
    color: '#4f46e5'
  }
]

// 事件处理函数
const onSearch = () => {
  router.push('/search')
}

const onUserCenter = () => {
  router.push('/profile')
}

const onQuickEntry = (item: any) => {
  router.push(item.route)
}

const onMoreJobs = () => {
  router.push('/jobs')
}

const onJobDetail = (job: any) => {
  router.push(`/job-detail/${job.id}`)
}
</script>

<style scoped>
.home-container {
  min-height: 100vh;
  background: linear-gradient(145deg, #f8fafc, #f1f5f9);
  padding-bottom: 50px;
}

.content {
  padding-top: 46px;
}

/* 导航栏样式 */
:deep(.van-nav-bar) {
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(10px);
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.05);
}

:deep(.van-nav-bar__title) {
  font-size: 18px;
  font-weight: 600;
  color: #1e293b;
}

/* 轮播图样式 */
.banner {
  height: 180px;
  margin: 16px;
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
}

.banner-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* 快速入口样式 */
.quick-entry {
  margin: 16px;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(10px);
  border-radius: 16px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.05);
  overflow: hidden;
}

:deep(.van-grid-item__content) {
  padding: 20px 8px;
  background: transparent;
}

:deep(.van-grid-item__icon) {
  font-size: 32px;
  color: #4f46e5;
  margin-bottom: 8px;
  transition: all 0.3s ease;
}

:deep(.van-grid-item__content:active .van-grid-item__icon) {
  transform: scale(1.1);
}

:deep(.van-grid-item__text) {
  font-size: 14px;
  color: #1e293b;
  font-weight: 500;
}

/* 热门工种样式 */
.section {
  margin: 16px;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(10px);
  border-radius: 16px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.05);
  overflow: hidden;
}

:deep(.van-cell) {
  padding: 16px;
  font-size: 18px;
  font-weight: 600;
  color: #1e293b;
}

.job-icon {
  width: 56px;
  height: 56px;
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 12px;
  background: linear-gradient(135deg, #4f46e5, #6366f1);
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.2);
  transition: all 0.3s ease;
}

:deep(.van-grid-item__content:active) .job-icon {
  transform: scale(1.05);
}

.job-info {
  text-align: left;
  padding: 8px 0;
}

.job-title {
  font-size: 16px;
  font-weight: 600;
  color: #1e293b;
  margin-bottom: 6px;
}

.job-price {
  font-size: 16px;
  background: linear-gradient(45deg, #4f46e5, #6366f1);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  font-weight: 600;
}

/* 平台优势样式 */
.section-header {
  padding: 20px 16px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.05);
}

.section-header h2 {
  font-size: 20px;
  font-weight: 600;
  color: #1e293b;
  margin: 0;
  position: relative;
}

.section-header h2::after {
  content: '';
  position: absolute;
  bottom: -20px;
  left: 0;
  width: 40px;
  height: 3px;
  background: linear-gradient(to right, #4f46e5, #6366f1);
  border-radius: 3px;
}

.features {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  padding: 16px;
}

.feature-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 24px 16px;
  background: linear-gradient(145deg, #ffffff, #f8fafc);
  border-radius: 16px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.03);
  transition: all 0.3s ease;
}

.feature-item:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.06);
}

.feature-title {
  font-size: 16px;
  font-weight: 600;
  color: #1e293b;
  margin: 16px 0 8px;
}

.feature-desc {
  font-size: 13px;
  color: #64748b;
  line-height: 1.5;
}
</style>
